package createThread.cn.tedu.threaddemo.lock;

import jdk.nashorn.internal.ir.CallNode;

class Test1{
    public int count = 0;
    public void add(){
        synchronized (this){
            count++;
        }
    }

}
public class Main {
    public static void main(String[] args) throws InterruptedException {
        Test1 test1 = new Test1();
        Thread t1 = new Thread(()->{
            for (int i = 1; i <= 50000 ; i++) {
                synchronized (test1){
                    test1.add();
                }
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 1; i <= 50000 ; i++) {
                synchronized (test1){
                    test1.add();
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(test1.count);
    }
}
